package com.TrainingCenter.dao.impl;

import com.TrainingCenter.dao.Dao;
import com.TrainingCenter.entity.Persitent;
import com.TrainingCenter.entity.PersonalData;
import org.hibernate.Query;


import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ibook
 * Date: 07.05.14
 * Time: 14:45
 * To change this template use File | Settings | File Templates.
 */
public class PersonalDataDaoImpl extends AbstractHibernateDao<PersonalData>  {

           @Override
    public void add(PersonalData persitent) {
    getSession().save(persitent);
    }

    @Override
    public void edit(PersonalData persitent) {
        getSession().update(persitent);
    }

    @SuppressWarnings("JpaQlInspection")
    @Override
    public void delete(int id) {
        Query query = getSession().createQuery("delete from personal_data where id_user=:id_user");
        query.setInteger("id_user",id);
        query.executeUpdate();
    }

    @Override
    public void delete(PersonalData Persitent) {
        getSession().delete(Persitent);
    }

    @Override
    public PersonalData get(int id) {
       return (PersonalData) getSession().load(PersonalData.class,id); //To change body of implemented methods use File | Settings | File Templates.
    }

    @SuppressWarnings("JpaQlInspection")
    @Override
    public List<PersonalData> getAllUser() {
        return getSession().createQuery("from personal_data").list();   //To change body of implemented methods use File | Settings | File Templates.
    }
}
